//
//  XDWebInfoCategoryListViewController.m
//  iphone.mobileoa
//
//  Created by 李亚春 on 13-5-24.
//  Copyright (c) 2013年 Epoint. All rights reserved.
//

#import "XDWebInfoCategoryListViewController.h"
#import "DBFrameService.h"
#import "CategoryInfoModel.h"
#import "XDWebInfoListViewController.h"

@interface XDWebInfoCategoryListViewController ()
{
    NSMutableArray *dataArray;
}
@end

@implementation XDWebInfoCategoryListViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    dataArray = [[DBFrameService getWebInfoCategoryByParent:@""]retain];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"simplecell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell==nil) {
        cell = [[UITableViewCell alloc]init];
    }
    
    CategoryInfoModel *m = [dataArray objectAtIndex:indexPath.row];
    cell.textLabel.text = m.CategoryName;
    cell.accessoryType = UITableViewCellSelectionStyleBlue;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    CategoryInfoModel *m = [dataArray objectAtIndex:indexPath.row];
    
    NSMutableArray *temp = [DBFrameService getWebInfoCategoryByParent:m.CategoryGuid];
    
    if (temp.count==0)
    {
        NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
        [params setObject:m.CategoryName forKey:@"viewtitle"];
        [params setObject:m.CategoryGuid forKey:@"categoryguid"];
        XDWebInfoListViewController *view = [[XDWebInfoListViewController alloc]initWithParams:params];
        [self.navigationController pushViewController:view animated:YES];
    }
    else{
        dataArray = [temp retain];
        [self.tv reloadData];
    }
}

- (void)dealloc {
    [_tv release];
    [super dealloc];
}
- (void)viewDidUnload {
    [dataArray release];
    [self setTv:nil];
    [super viewDidUnload];
}
@end
